<!DOCTYPE html>
<html lang="zh">
<head>
    <title>登录</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../asset/lib/layui/css/layui.css">
    <link rel="stylesheet" href="../asset/css/common.css">
    <script src="../asset/lib/jquery321.min.js"></script>
    <script src="../asset/js/core.js"></script>
    <!-- 登录界面样式 -->
    <link rel="stylesheet" href="../asset/css/login.css">
    <link rel="stylesheet" href="../asset/css/admin.css">
    <link rel="stylesheet" href="../asset/css/layer.css">
    <!-- END：登录界面样式 -->
</head>
<body class="layui-layout-body" layadmin-themealias="default">
<div class="layui-layout layui-layout-admin">
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>登录</h2>
                <p>个人信息管理中心</p>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form" lay-filter="user-login-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                           for="LAY-user-login-username"></label>
                    <input autocomplete="off" type="text" name="username" id="LAY-user-login-username"
                           lay-verify="required"
                           placeholder="登录名" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-password"></label>
                    <input autocomplete="off" type="password" name="password" id="LAY-user-login-password"
                           lay-verify="required"
                           placeholder="密码" class="layui-input">
                </div>
                <div class="layui-form-item" style="margin-bottom: 20px;padding-top: 7px;">
                    <a href="forget.html" class="layadmin-link"
                       style="margin-top: 7px;">忘记密码？</a>
                    <a href="register.html" class="layadmin-user-jump-change layadmin-link">注册账号</a>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit="" lay-filter="user-login-submit">登 入
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 代码库导入 -->
<script src="../asset/lib/layui/layui.js"></script>
<script src="../asset/js/layui-elem.js"></script>
<!-- END:代码库导入 -->
<!-- ================================在这里编写页面的js代码================================ -->
<script>
    layui.use(['form', 'element', 'layer'], function () {
        var form = layui.form,
            element = layui.element,
            layer = layui.layer;

        //监听提交
        form.on('submit(user-login-submit)', function (data) {
            // 首先配置记住密码
            var userInfo = {
                "username": data.field.username,
                "password": data.field.password
            };
            layer.msg("正在登录", {
                icon: 16,
                time: 10000
            })
            util.httpRequest.post("../login", userInfo, function (msg) {
                layer.closeAll();
                if (msg.code === 200) {
                    layer.msg('登录成功', {
                        offset: '50px'
                        , icon: 1
                        , time: 1000
                    });
                    //把登录用户数据保存到浏览器
                    util.data.set("userInfo", msg.result);
                    setTimeout(function () {
                        window.location.href = "userinfo.html";
                    }, 1000)
                } else {
                    layer.msg(msg.errorMessage, {
                        offset: '50px'
                        , icon: 2
                        , time: 2000
                    });
                }
            });
            return false;
        });
    });
</script>
<!-- ================================END:在这里编写页面的js代码================================ -->
</body>
</html>